/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alerts;

import ghanaroutes.entities.Routes;
import ghanaroutes.entities.Users;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author ben
 */


@Entity
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Alert.findAll", query = "SELECT b FROM Alert b"),
    @NamedQuery(name = "Alert.findById", query = "SELECT b FROM Alert b WHERE b.id = :alertId"),
    @NamedQuery(name = "Alert.findByAreaName", query = "SELECT b FROM Alert b WHERE b.areaName = :areaName"),
    @NamedQuery(name = "Alert.findByCause" , query="SELECT b from Alert b WHERE b.cause = :cause"),
    @NamedQuery(name = "Alert.findByAreaNameANDCause", query="SELECT b from Alert b WHERE b.areaName = :areaName AND b.cause=:cause"),
    @NamedQuery(name = "Alert.findByAreaNameORCause", query="SELECT b from Alert b WHERE b.areaName = :areaName OR b.cause=:cause")
    })
public class Alert implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String location; // Current longitude and latitude
    private String cause;
    private String areaName;
    
    
    // Date Section
    //@Temporal(javax.persistence.TemporalType.DATE)
    @Temporal(TemporalType.TIMESTAMP)
    private Date alertCreated;
    
    //@Temporal(javax.persistence.TemporalType.DATE)
    @Temporal(TemporalType.TIMESTAMP)

    private Date alertPast;
    
    private int active ;

    public Alert() {
        this.alertCreated = new Date();
        this.active = 0;
    }
    
    

    public Date getAlertCreated() {
        return alertCreated;
    }

    public void setAlertCreated(Date alertCreated) {
        this.alertCreated = alertCreated;
    }

    public Date getAlertPast() {
        return alertPast;
    }

    public void setAlertPast(Date alertPast) {
        this.alertPast = alertPast;
    }

    public int getActive() {
        return active;
    }

    public void setActive(int active) {
        this.active = active;
    }
  
    
    
    // An alert can be traced to a user
    @ManyToOne
    @JoinColumn(name="user_id")
    private Users user;

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }
    
    
    
    
    
    // Mappings for Alert Group
    @ManyToOne
    @JoinColumn(name="alert_group_id")
    private AlertGroup alertGroup;
    
    @ManyToOne
    @JoinColumn(name="route_id")
    private Routes route;

    public Routes getRoute() {
        return route;
    }

    public void setRoute(Routes route) {
        this.route = route;
    }
    
    

    public AlertGroup getAlertGroup() {
        return alertGroup;
    }

    public void setAlertGroup(AlertGroup alertGroup) {
        this.alertGroup = alertGroup;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }
    
    
    
    
    

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCause() {
        return cause;
    }

    public void setCause(String cause) {
        this.cause = cause;
    }
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Alert)) {
            return false;
        }
        Alert other = (Alert) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.alerts.Alert[ id=" + id + " ]";
    }
    
}
